package com.cnhaimei.vod.logic;

import java.util.List;

import android.R.integer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.cnhaimei.base.TransparentActivity;
import com.cnhaimei.vod.R;
import com.cnhaimei.vod.net.XVod;
import com.cnhaimei.vod.net.dc.CallService;
import com.cnhaimei.vod.net.dc.CallService.ServiceItem;
import com.cnhaimei.vod.net.dc.Player;
import com.cnhaimei.vod.util.Const;

/**
 * 服务选择界面
 * 
 * @author funwell <br>
 * @date 2013-8-19
 * 
 */
public class ServiceActivity extends TransparentActivity implements OnClickListener{
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.v8_service);
		
		setClickable(R.id.service1, R.id.service2, R.id.service3, R.id.service4, R.id.service5, R.id.service6, R.id.service7, R.id.service8);
		
		initView();
	}
	
	private void initView() {
		int ids[] = {R.id.service1, R.id.service2, R.id.service3, R.id.service4, R.id.service5, R.id.service6, R.id.service7, R.id.service8};
		List<String> list = CallService.G().getItems();
		int nCount = 0;
		for (int i = 0; list != null && i < list.size(); i++) {

			ServiceItem item = CallService.G().parse(list.get(i));
			if (item != null && item.getIndex() > -1) {
				TextView textView = (TextView) findViewById(ids[nCount++]);
				textView.setText(item.getName());
				textView.setTag(item.getIndex());
				textView.setVisibility(View.VISIBLE);
			}
		}		
		
		for (int i = nCount; i < ids.length; i++) {
			TextView textView = (TextView) findViewById(ids[nCount++]);
			textView.setVisibility(View.GONE);
		}
	}
	
	@Override
	public void onClick(View v) {
		int i = -1;
		switch (v.getId()) {
		case R.id.service1:// 
		case R.id.service2:
		case R.id.service3:
		case R.id.service4:
		case R.id.service5:
		case R.id.service6:
		case R.id.service7:
		case R.id.service8:
			i = (Integer)v.getTag();
			break;
		default:
			break;
		}
		
		if (i > -1) {
			XVod.G().callServer(String.valueOf(i));
			//showMyToast(this.getResources().getString(R.string.call_service_success));//服务信息已发出		
		}
		
		finish();
		setResult(Const.ResultCode.CALL_SERVICE_END);
	}
	
}
